/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frontera;

import entidad.Lote;
import entidad.Producto;
import entidad.Transferencia;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.SpinnerNumberModel;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;

/**
 *
 * @author Andrés,Daniel,Osmond
 */
public class RealizarTransferencias extends javax.swing.JPanel {

    private VentanaPrincipal ventanaPe;

    public RealizarTransferencias(VentanaPrincipal v) {
        initComponents();
        this.ventanaPe = v;
        //limpiar();

        productoCB.setModel(new DefaultComboBoxModel(VentanaPrincipal.controlProducto.buscar("").toArray()));
        //cargarLotes((Producto) productoCB.getSelectedItem());
        productoCB.setSelectedIndex(-1);
        cargaRB.setEnabled(false);
        descargaRB.setEnabled(false);
        devolucionRB.setEnabled(false);

        disableAll();

        //cargarInformacionLote();
    }

    public void disableAll() {
        numLoteTF.setEnabled(false);
        diaCB.setEnabled(false);
        mesCB.setEnabled(false);
        yearCB.setEnabled(false);
        cantidadS.setEnabled(false);

        loteCB.setEnabled(false);
        uTransicionS.setEnabled(false);

        descripcionT.setEnabled(false);
        aceptarB.setEnabled(false);
    }

    public void limpiar() {
        quitarAvisos();

        productoCB.setSelectedItem(null);

        numLoteTF.setText("");
        diaCB.setSelectedItem(null);
        mesCB.setSelectedItem(null);
        yearCB.setSelectedItem(null);
        cantidadS.setValue(0);

        loteCB.setSelectedItem(null);
        uDispoiblesS.setText("0");
        uTransicionS.setValue(0);
        uResultantesS.setText("0");

        operaciones.clearSelection();
        descripcionT.setText("Descripción");

        //op1.setSelected(true);

        disableAll();
        
        
//        cargarLotes((Producto) productoCB.getSelectedItem());
//        cargarInformacionLote();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        operaciones = new javax.swing.ButtonGroup();
        productoCB = new javax.swing.JComboBox();
        productoL = new javax.swing.JLabel();
        titulo = new javax.swing.JLabel();
        imagen = new javax.swing.JLabel();
        aceptarB = new javax.swing.JButton();
        cancelarB = new javax.swing.JButton();
        spDescripcion = new javax.swing.JScrollPane();
        descripcionT = new javax.swing.JTextArea();
        avisoTF = new javax.swing.JLabel();
        contenido = new javax.swing.JPanel();
        cargas = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        numLoteTF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        diaCB = new javax.swing.JComboBox();
        mesCB = new javax.swing.JComboBox();
        yearCB = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        cantidadS = new javax.swing.JSpinner();
        descargasYDevoluciones = new javax.swing.JPanel();
        uDispoiblesL = new javax.swing.JLabel();
        uResultantesL = new javax.swing.JLabel();
        uTransicionL = new javax.swing.JLabel();
        uDispoiblesS = new javax.swing.JLabel();
        uResultantesS = new javax.swing.JLabel();
        uTransicionS = new javax.swing.JSpinner();
        loteL = new javax.swing.JLabel();
        loteCB = new javax.swing.JComboBox();
        panelTipoOperacion = new javax.swing.JPanel();
        cargaRB = new javax.swing.JRadioButton();
        descargaRB = new javax.swing.JRadioButton();
        devolucionRB = new javax.swing.JRadioButton();

        productoCB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        productoCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Producto 1", "Producto 2", "Producto 3" }));
        productoCB.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                productoCBFocusGained(evt);
            }
        });

        productoL.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        productoL.setText("Selecciona el producto:");

        titulo.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
        titulo.setForeground(new java.awt.Color(255, 255, 255));
        titulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titulo.setText("Transferencias");

        imagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icono2.png"))); // NOI18N

        aceptarB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        aceptarB.setText("Aceptar");
        aceptarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarBActionPerformed(evt);
            }
        });

        cancelarB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        cancelarB.setText("Cancelar");
        cancelarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarBActionPerformed(evt);
            }
        });

        descripcionT.setColumns(20);
        descripcionT.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        descripcionT.setRows(5);
        descripcionT.setText("Descripción");
        descripcionT.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                descripcionTMouseClicked(evt);
            }
        });
        descripcionT.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                descripcionTFocusLost(evt);
            }
        });
        spDescripcion.setViewportView(descripcionT);

        avisoTF.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        avisoTF.setForeground(new java.awt.Color(204, 0, 0));
        avisoTF.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        contenido.setLayout(new java.awt.GridLayout(1, 0));

        cargas.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cargas", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel3.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        jLabel3.setText("Numero de Lote");

        numLoteTF.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        jLabel1.setText("Fecha de Vencimiento");

        diaCB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        diaCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "DD", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        mesCB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        mesCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MM", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));

        yearCB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        yearCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AAAA", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        jLabel2.setText("Cantidad");

        cantidadS.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        cantidadS.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));

        javax.swing.GroupLayout cargasLayout = new javax.swing.GroupLayout(cargas);
        cargas.setLayout(cargasLayout);
        cargasLayout.setHorizontalGroup(
            cargasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cargasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(cargasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cargasLayout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(numLoteTF))
                    .addGroup(cargasLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(diaCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(mesCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(yearCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 14, Short.MAX_VALUE))
                    .addGroup(cargasLayout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cantidadS)))
                .addContainerGap())
        );
        cargasLayout.setVerticalGroup(
            cargasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cargasLayout.createSequentialGroup()
                .addGroup(cargasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(numLoteTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(cargasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addGroup(cargasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(diaCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mesCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(yearCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(cargasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cantidadS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 60, Short.MAX_VALUE))
        );

        contenido.add(cargas);

        descargasYDevoluciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Descargas y/o Devoluciones", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        uDispoiblesL.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        uDispoiblesL.setText("Unidades disponibles: ");

        uResultantesL.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        uResultantesL.setText("Unidades resultantes:");

        uTransicionL.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        uTransicionL.setText("Unidades en transición: ");

        uDispoiblesS.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        uDispoiblesS.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uDispoiblesS.setText("0");

        uResultantesS.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        uResultantesS.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uResultantesS.setText("0");

        uTransicionS.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        uTransicionS.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        uTransicionS.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                uTransicionSMouseClicked(evt);
            }
        });
        uTransicionS.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                uTransicionSStateChanged(evt);
            }
        });
        uTransicionS.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                uTransicionSKeyPressed(evt);
            }
        });

        loteL.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        loteL.setText("Selecciona el lote:");

        loteCB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        loteCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lote 1" }));
        loteCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loteCBActionPerformed(evt);
            }
        });
        loteCB.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                loteCBFocusGained(evt);
            }
        });

        javax.swing.GroupLayout descargasYDevolucionesLayout = new javax.swing.GroupLayout(descargasYDevoluciones);
        descargasYDevoluciones.setLayout(descargasYDevolucionesLayout);
        descargasYDevolucionesLayout.setHorizontalGroup(
            descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(descargasYDevolucionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, descargasYDevolucionesLayout.createSequentialGroup()
                        .addComponent(loteL, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
                        .addContainerGap())
                    .addComponent(loteCB, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(descargasYDevolucionesLayout.createSequentialGroup()
                        .addGroup(descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(uDispoiblesL, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(uTransicionL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(uResultantesL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(uDispoiblesS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(uResultantesS, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(uTransicionS, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        descargasYDevolucionesLayout.setVerticalGroup(
            descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, descargasYDevolucionesLayout.createSequentialGroup()
                .addComponent(loteL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(loteCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(uDispoiblesL)
                    .addComponent(uDispoiblesS))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(uTransicionL)
                    .addComponent(uTransicionS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(descargasYDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(uResultantesL)
                    .addComponent(uResultantesS))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        contenido.add(descargasYDevoluciones);
        descargasYDevoluciones.getAccessibleContext().setAccessibleName("descargasYDevoluciones");

        panelTipoOperacion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tipo Operación", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        panelTipoOperacion.setLayout(new java.awt.GridLayout(1, 0));

        operaciones.add(cargaRB);
        cargaRB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        cargaRB.setText(Transferencia.carga);
        cargaRB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cargaRBActionPerformed(evt);
            }
        });
        panelTipoOperacion.add(cargaRB);

        operaciones.add(descargaRB);
        descargaRB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        descargaRB.setText(Transferencia.descarga);
        descargaRB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                descargaRBActionPerformed(evt);
            }
        });
        panelTipoOperacion.add(descargaRB);

        operaciones.add(devolucionRB);
        devolucionRB.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        devolucionRB.setText(Transferencia.devolucion);
        devolucionRB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                devolucionRBActionPerformed(evt);
            }
        });
        panelTipoOperacion.add(devolucionRB);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(titulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(imagen))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(avisoTF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(spDescripcion)
                            .addComponent(contenido, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(panelTipoOperacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(productoL)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(productoCB, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(aceptarB, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cancelarB)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imagen)
                    .addComponent(titulo))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(productoCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(productoL))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelTipoOperacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(contenido, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(spDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(avisoTF, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelarB)
                    .addComponent(aceptarB))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void loteCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loteCBActionPerformed
        cargarInformacionLote();
    }//GEN-LAST:event_loteCBActionPerformed

    private void cancelarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarBActionPerformed
        quitarAvisos();
        limpiar();
    }//GEN-LAST:event_cancelarBActionPerformed

    private void devolucionRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_devolucionRBActionPerformed
        if (productoCB.getSelectedItem() != null) {
            quitarAvisos();
            disableAll();

            loteCB.setEnabled(true);
            uTransicionS.setEnabled(true);
            descripcionT.setEnabled(true);

            uTransicionS.setValue(0);
            actualizarResultantes();
            Lote l = (Lote) loteCB.getSelectedItem();
            if (l == null) {
                return;
            }
            uTransicionS.setModel(new SpinnerNumberModel(0, 0, l.getCantidad(), 1));
        }
    }//GEN-LAST:event_devolucionRBActionPerformed

    private void descargaRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_descargaRBActionPerformed
        if (productoCB.getSelectedItem() != null) {
            quitarAvisos();
            disableAll();

            loteCB.setEnabled(true);
            uTransicionS.setEnabled(true);
            descripcionT.setEnabled(true);
            uTransicionS.setValue(0);
            actualizarResultantes();
            Lote l = (Lote) loteCB.getSelectedItem();
            if (l == null) {
                return;
            }
            loteCB.setSelectedIndex(0);
            uTransicionS.setModel(new SpinnerNumberModel(0, 0, l.getCantidad(), 1));
        }
    }//GEN-LAST:event_descargaRBActionPerformed

    private void cargaRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cargaRBActionPerformed
        if (productoCB.getSelectedItem() != null) {
            quitarAvisos();
            disableAll();

            numLoteTF.setEnabled(true);
            diaCB.setEnabled(true);
            mesCB.setEnabled(true);
            yearCB.setEnabled(true);
            cantidadS.setEnabled(true);

            descripcionT.setEnabled(true);
            aceptarB.setEnabled(true);
        }
    }//GEN-LAST:event_cargaRBActionPerformed

    private void aceptarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarBActionPerformed
//        ControlTransferencias controlTransferencias = mainFrame.getControlTransferencias();

        Lote l = null;
        String motivo = "";
        int cantidad = 0;

        if (cargaRB.isSelected()) {
            motivo = cargaRB.getText();
            try {
//                Date fv = new Date((int)yearCB.getSelectedItem(), (int)mesCB.getSelectedItem(), (int)diaCB.getSelectedItem());
                /*Implementacion opcional que mantiene al Date y le 
                 * quita el deprecated, simplemente instancia indirectamente
                 * el campo de fechadeVencimiento
                */
                String t = (int)yearCB.getSelectedItem()+"-"+
                           (int)mesCB.getSelectedItem()+"-"+
                           (int)diaCB.getSelectedItem();
                Date fv = new DateTime(DateTime.parse(t, DateTimeFormat.forPattern("yyyy/MM/dd"))).toDate();
                cantidad = (int) cantidadS.getValue();

                l = new Lote(Integer.parseInt(numLoteTF.getText()), fv, cantidad);
                if (!VentanaPrincipal.controlLote.validarLote(l)) {
                    return;
                }
            } catch (NumberFormatException e) {
            }
        }

        if (descargaRB.isSelected()) {
            motivo = descargaRB.getText();
            l = (Lote) loteCB.getSelectedItem();
            cantidad = (int) uTransicionS.getValue();
            l.setCantidad(Integer.parseInt(uResultantesS.getText()));
        }
        if (devolucionRB.isSelected()) {
            motivo = devolucionRB.getText();
            l = (Lote) loteCB.getSelectedItem();
            cantidad = (int) uTransicionS.getValue();
            l.setCantidad(Integer.parseInt(uResultantesS.getText()));
        }

        String descripcion = descripcionT.getText();
        if (descripcion.equals("Descripción")) {
            descripcion = "";
        }

        Transferencia t = new Transferencia(new Date(),
                (Producto) productoCB.getSelectedItem(),
                l, motivo, cantidad, descripcion);

        if (VentanaPrincipal.controlTransferencia.validarTransferencia(t)) {
            limpiar();
            VentanaPrincipal.controlTransferencia.realizarTransferencia(t);
            cargarLotes(t.getProducto());
            avisoTF.setText("Transferencia realizada");
            descripcionT.setText("Descripción");
        }
    }//GEN-LAST:event_aceptarBActionPerformed

    private void productoCBFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_productoCBFocusGained
//        productoCB.setModel(new DefaultComboBoxModel(ventanaP.getControlProductos().getSistemaProducto().getProductos().toArray()));
        productoCB.setModel(new DefaultComboBoxModel(VentanaPrincipal.controlProducto.buscar("").toArray()));
        cargarInformacionLote();
    }//GEN-LAST:event_productoCBFocusGained

    private void loteCBFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_loteCBFocusGained
        cargarLotes((Producto) productoCB.getSelectedItem());
        cargarInformacionLote();
    }//GEN-LAST:event_loteCBFocusGained

    private void descripcionTMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_descripcionTMouseClicked
        quitarAvisos();
        if (descripcionT.getText().contains("Descripción") && (cargaRB.isSelected() || descargaRB.isSelected() || devolucionRB.isSelected())) {
            descripcionT.setText("");
        }
    }//GEN-LAST:event_descripcionTMouseClicked

    private void descripcionTFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_descripcionTFocusLost
        if (descripcionT.getText().equals("") && (cargaRB.isSelected() || descargaRB.isSelected() || devolucionRB.isSelected())) {
            descripcionT.setText("Descripción");
        }
    }//GEN-LAST:event_descripcionTFocusLost

    private void uTransicionSKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_uTransicionSKeyPressed
        quitarAvisos();
        Lote l = (Lote) loteCB.getSelectedItem();
        if (l == null) {
            return;
        }
        uDispoiblesS.setText("" + l.getCantidad());
    }//GEN-LAST:event_uTransicionSKeyPressed

    private void uTransicionSStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_uTransicionSStateChanged
        actualizarResultantes();
    }//GEN-LAST:event_uTransicionSStateChanged

    private void uTransicionSMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uTransicionSMouseClicked
        quitarAvisos();
        Lote l = (Lote) loteCB.getSelectedItem();
        if (l == null) {
            return;
        }
        uDispoiblesS.setText("" + l.getCantidad());
    }//GEN-LAST:event_uTransicionSMouseClicked

    public void actualizarResultantes() {
        quitarAvisos();
        int t = (int) uTransicionS.getValue();
        uResultantesS.setText("" + (Integer.parseInt(uDispoiblesS.getText()) - t));
    }

    private void cargarLotes(Producto p) {
        if (p == null) {
            return;
        }
        loteCB.setModel(new DefaultComboBoxModel(p.getLotes().toArray()));
        loteCB.setEnabled(true);
    }

    private void cargarInformacionLote() {
        quitarAvisos();

        uTransicionS.setEnabled(true);
        aceptarB.setEnabled(true);
        Lote l = (Lote) loteCB.getSelectedItem();
        if (l == null) {
            return;
        }
        uDispoiblesS.setText("" + l.getCantidad());
        uTransicionS.setModel(new SpinnerNumberModel(0, 0, 9999999, 1));
        uTransicionS.setValue(0);
        uResultantesS.setText("" + l.getCantidad());
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptarB;
    private javax.swing.JLabel avisoTF;
    private javax.swing.JButton cancelarB;
    private javax.swing.JSpinner cantidadS;
    private javax.swing.JRadioButton cargaRB;
    private javax.swing.JPanel cargas;
    private javax.swing.JPanel contenido;
    private javax.swing.JRadioButton descargaRB;
    private javax.swing.JPanel descargasYDevoluciones;
    private javax.swing.JTextArea descripcionT;
    private javax.swing.JRadioButton devolucionRB;
    private javax.swing.JComboBox diaCB;
    private javax.swing.JLabel imagen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JComboBox loteCB;
    private javax.swing.JLabel loteL;
    private javax.swing.JComboBox mesCB;
    private javax.swing.JTextField numLoteTF;
    private javax.swing.ButtonGroup operaciones;
    private javax.swing.JPanel panelTipoOperacion;
    private javax.swing.JComboBox productoCB;
    private javax.swing.JLabel productoL;
    private javax.swing.JScrollPane spDescripcion;
    private javax.swing.JLabel titulo;
    private javax.swing.JLabel uDispoiblesL;
    private javax.swing.JLabel uDispoiblesS;
    private javax.swing.JLabel uResultantesL;
    private javax.swing.JLabel uResultantesS;
    private javax.swing.JLabel uTransicionL;
    private javax.swing.JSpinner uTransicionS;
    private javax.swing.JComboBox yearCB;
    // End of variables declaration//GEN-END:variables

    private void quitarAvisos() {
        avisoTF.setText("");
    }
}
